<script src="<?php echo Yii::app()->request->baseUrl; ?>/js/plugins/validate/jquery.validate.js"></script>
<script src="<?php echo Yii::app()->request->baseUrl; ?>/js/demos/demo.validate.js"></script>
<div class="widget-content">
	<?php $form=$this->beginWidget('CActiveForm', array(
			'id'=>'film-form',
			'enableAjaxValidation'=>false,
			'htmlOptions'=>array('class'=>'form-horizontal', 'novalidate'=>'novalidate','enctype' => 'multipart/form-data'),
	)); ?>
	<?php if($form->errorSummary($model)):?>
			<div class="alert alert-block">
				<a class="close" data-dismiss="alert" href="#">&times;</a>
				<h4 class="alert-heading"><?php echo $form->errorSummary($model); ?></h4>
			</div>
	<?php endif;?>
	<fieldset>
	<div class="control-group">
		<?php echo $form->labelEx($model,'name',array('class'=>'control-label','for'=>'name')); ?>
		<div class="controls">
			<?php echo $form->textField($model,'name',array('size'=>60,'maxlength'=>300,'class'=>'input-large')); ?>
			<?php echo $form->error($model,'name'); ?>
		</div>
	</div>
	<div class="control-group">
		<?php echo $form->labelEx($model,'image',array('class'=>'control-label','for'=>'image')); ?>
		<div class="controls">
			<?php $this->widget('ext.kcfinder.EImageFinder',array('model'=>$model,'fieldName'=>'image','type'=>'images'));?>
			<?php echo $form->error($model,'image'); ?>
			<div id="ckeditor">
			</div>
			<?php if($model->image){
					echo '<div><img src="'.$model->image.'" style="max-width:150px"/></div>';
				}
			?>
		</div>
	</div>
	<div class="control-group">
		<?php echo $form->labelEx($model,'clip_url',array('class'=>'control-label','for'=>'clip_url')); ?>
		<div class="controls">
			<?php $this->widget('ext.kcfinder.EImageFinder',array('model'=>$model,'fieldName'=>'clip_url','type'=>'files'));?>
			<?php echo $form->error($model,'clip_url'); ?>
			<div id="ckeditor">
			</div>
		</div>
	</div>
	<div class="control-group">
		<?php echo $form->labelEx($model,'introtext',array('class'=>'control-label','for'=>'introtext')); ?>
		<div class="controls">
			<?php echo $form->textArea($model,'introtext',array('rows'=>6, 'cols'=>50,'class'=>'input-large')); ?>
			<?php echo $form->error($model,'introtext'); ?>
		</div>
	</div>
	<div class="control-group">
		<?php echo $form->labelEx($model,'description',array('class'=>'control-label','for'=>'description')); ?>
		<div class="controls">
			<?php //echo $form->textArea($model,'description',array('rows'=>6, 'cols'=>50,'class'=>'input-large')); ?>
			<?php 
				$this->widget('application.extensions.KCEditor.KCEditor',array(
					'model'=>$model,				# Data-Model (form model)
					'attribute'=>'description',			# Attribute in the Data-Model
					'height'=>'400px',
					'width'=>'100%',
				) );
			?>
			<?php echo $form->error($model,'trailer_link'); ?>
		</div>	
	</div>
	<div class="control-group">
				<?php echo $form->labelEx($model,'tags',array('class'=>'control-label','for'=>'tags')); ?>
				<div class="controls">
					<div id="tags-group" class="alert alert-success">
					</div>
					<div>
						<input type="text" class="input-large" id="txttags">
						<a id="add_tag" class="btn">Add</a>
					</div>
					<?php echo $form->hiddenField($model,'tags'); ?>
				</div>
	</div>
	<?php echo $form->hiddenField($model,'order'); ?>
			
	<?php echo $form->hiddenField($model,'global_order'); ?>
			
	<div class="control-group">
			<?php echo $form->labelEx($model,'Category',array('class'=>'control-label','for'=>'cid')); ?>
		<div class="controls">
			<?php echo $form->dropDownList($model,'cid', $categories); ?>
			<?php echo $form->error($model,'cid'); ?>
		</div>
	</div>
	<div class="control-group">
				<?php echo $form->labelEx($model,'price',array('class'=>'control-label','for'=>'price')); ?>
				<div class="controls">
				<?php echo $form->dropDownList($model,'price', $package); ?>
				<?php echo $form->error($model,'price'); ?>
				</div>
	</div>
	<div class="control-group">
				<?php echo $form->labelEx($model,'createddate',array('class'=>'control-label','for'=>'createddate')); ?>
				<div class="controls">
					<input id="datepicker-inline" placeholder="Select date" type="text" value="<?php if($model){echo date("d-m-Y", strtotime($model->createddate));}?>">
					<?php echo $form->hiddenField($model,'createddate'); ?>
					<?php echo $form->error($model,'createddate'); ?>
				</div>
	</div>
	<div class="control-group">
				<?php echo $form->labelEx($model,'hot',array('class'=>'control-label','for'=>'hot')); ?>
				<div class="controls">
					<div class="btn-group" data-toggle="buttons-radio">
					       <button onclick="document.getElementById('Clip_hot').value=1;return false;" class="btn btn-primary <?php if($model->hot=='1'){echo 'active';}?>">True</button>
					       <button onclick="document.getElementById('Clip_hot').value=0;return false;" class="btn btn-primary <?php if($model->hot=='0'){echo 'active';}?>">False</button>
					 </div>
					 <?php echo $form->hiddenField($model,'hot'); ?>
					<?php echo $form->error($model,'hot'); ?>
				</div>
				
		</div>
		
		<div class="control-group">
				<?php echo $form->labelEx($model,'global_hot',array('class'=>'control-label','for'=>'global_hot')); ?>
				<div class="controls">
					 <div class="btn-group" data-toggle="buttons-radio">
					       <button onclick="document.getElementById('Clip_global_hot').value=1;return false;" class="btn btn-primary <?php if($model->global_hot=='1'){echo 'active';}?>">True</button>
					       <button onclick="document.getElementById('Clip_global_hot').value=0;return false;" class="btn btn-primary  <?php if($model->global_hot=='0'){echo 'active';}?>">False</button>
					 </div>
					 <?php echo $form->hiddenField($model,'global_hot'); ?>
					 <?php echo $form->error($model,'global_hot'); ?>
				</div>
				
		</div>
		<?php if(Yii::app()->user->role=='superadmin' || Yii::app()->user->role=='admin'|| Yii::app()->user->role=='manager'):?>
		<div class="control-group">
				<?php echo $form->labelEx($model,'active',array('class'=>'control-label','for'=>'active')); ?>
				<div class="controls">
				
					<div class="btn-group" data-toggle="buttons-radio">
				       <button onclick="document.getElementById('Clip_active').value=1;return false;" class="btn btn-primary <?php if($model->active=='1'){echo 'active';}?>">True</button>
				       <button onclick="document.getElementById('Clip_active').value=0;return false;" class="btn btn-primary <?php if($model->active=='0'){echo 'active';}?>">False</button>
				 	</div>
				 	<?php echo $form->hiddenField($model,'active'); ?>
					<?php echo $form->error($model,'active'); ?>
				</div>
				
		</div>
		<?php endif;?>
		<div class="form-actions">
				<?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save',array('class'=>'btn btn-primary btn-large')); ?>
				<?php echo CHtml::link('Cancel',array('/clip/admin'),array('class'=>'btn btn-large')); ?>
		</div>
	</fieldset>
<?php $this->endWidget(); ?>

</div><!-- form -->
<?php 
	Yii::app()->clientScript->registerScript('helloscript',
		'$("#datepicker-inline").datepicker({onSelect: showDate});
		var currentDate = new Date();  
		$("#datepicker-inline").datepicker("setDate",currentDate);
		$("#Clip_createddate").val((currentDate.getMonth()+1)+"/"+currentDate.getDate()+"/"+currentDate.getFullYear());
		function showDate(date) {
			$("#Clip_createddate").val(date);
		}',CClientScript::POS_READY);
?>
<script type="text/javascript">
	$(document).ready(function() {
		
		var tags=$("#Clip_tags").val();
		var arr=tags.split(';');
		$.each(arr,function(index,item){
			if(item!=''){
				$("#tags-group").append('<a style="margin-right:3px;margin-bottom:3px;" class="btn btn-secondary btn-mini">'+item+'<i class="icon-remove"></i></a>');
			}
		});
		$('a.btn-mini').click(function(){
			var key=$(this).text();
			arr=$.grep(arr, function(value) {
				  return value != key;
			});
			$.each(arr,function(index,item){
				if(index==0){
					tags=item;
				}
				else{
					tags+=';'+item;
				}
			});
			$("#Film_tags").val(tags);
			$(this).remove();
		});
	});
	$('#add_tag').click(function(){
		$("#txttags").val($("#txttags").val().trim());
		if($("#txttags").val()!=''){
			var tags=$("#Clip_tags").val();
			if(tags==''){
				tags=$("#txttags").val();
			}
			else{
				tags+=';'+$("#txttags").val();
			}
			$("#Clip_tags").val(tags);
			$("#tags-group").append('<a style="margin-right:3px;margin-bottom:3px;" class="btn btn-secondary btn-mini">'+$("#txttags").val()+'<i class="icon-remove"></i></a>');
			$('a.btn-mini').click(function(){
				var key=$(this).text();
				var arr=tags.split(';');
				
				arr=$.grep(arr, function(value) {
					  return value != key;
				});
				$.each(arr,function(index,item){
					if(index==0){
						tags=item;
					}
					else{
						tags+=';'+item;
					}
				});
				$("#Clip_tags").val(tags);
				$(this).remove();
			});
			$("#txttags").val('');
		}
	});
</script>